package com.htthorizon.powersupply.controller;

import com.htthorizon.powersupply.async.ApiScheduling;
import com.htthorizon.powersupply.async.AsyncData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.net.URISyntaxException;

/**
 * @author Brilliant
 */
@RestController
@RequestMapping("/test")
public class ApiController {

    @Autowired
    private AsyncData asyncData;
    @Autowired
    private ApiScheduling apiScheduling;

    @GetMapping("/getdata")
    public String getData() throws URISyntaxException, IOException {
        asyncData.asyncDataRealTimePowerOutage();
        asyncData.asyncDataRealTimePowerOutageUser();
        asyncData.getGridTgCurDf();
        asyncData.getGridTgPowerDf();
        asyncData.getGridTgVoltDf();
        asyncData.getUserLowVoltageData();
        asyncData.getLineLoad();
        return "success";
    }

    @GetMapping("/getLoadMonitor")
    public String computeLoadFactor() throws URISyntaxException, IOException {
        apiScheduling.computeLoadFactor();
        return "success";
    }

    @GetMapping("/userLowVoltageData")
    public String getUserLowVoltageData() throws URISyntaxException, IOException {
        asyncData.getUserLowVoltageData();
        return "success";
    }

    @GetMapping("/realTimePowerOutage")
    public String getRealTimePowerOutage() throws URISyntaxException, IOException {
        asyncData.asyncDataRealTimePowerOutage();
        return "success";
    }

    @GetMapping("/realTimePowerOutageUser")
    public String getRealTimePowerOutageUser() throws URISyntaxException, IOException {
        asyncData.asyncDataRealTimePowerOutageUser();
        return "success";
    }

    @GetMapping("/gridTgCurDf")
    public String getGridTgCurDf() throws URISyntaxException, IOException {
        asyncData.getGridTgCurDf();
        return "success";
    }

    @GetMapping("/gridTgPowerDf")
    public String getGridTgPowerDf() throws URISyntaxException, IOException {
        asyncData.getGridTgPowerDf();
        return "success";
    }

    @GetMapping("/gridTgVoltDf")
    public String getGridTgVoltDf() throws URISyntaxException, IOException {
        asyncData.getGridTgVoltDf();
        return "success";
    }

    @GetMapping("/lineLoad")
    public String getLineLoad() throws URISyntaxException, IOException {
        asyncData.getLineLoad();
        return "success";
    }

}
